<?php 
$statusArr = array(Leave::LEAVE_STATUS_LEAVE_REJECTED => $lang_Leave_Common_Rejected,
                   Leave::LEAVE_STATUS_LEAVE_CANCELLED => $lang_Leave_Common_Cancelled,
                   Leave::LEAVE_STATUS_LEAVE_PENDING_APPROVAL => $lang_Leave_Common_PendingApproval,
                   Leave::LEAVE_STATUS_LEAVE_APPROVED => $lang_Leave_Common_Approved,
                   Leave::LEAVE_STATUS_LEAVE_TAKEN => $lang_Leave_Common_Taken,
                   LeaveRequests::LEAVEREQUESTS_MULTIPLESTATUSES => $lang_Leave_Common_StatusDiffer);
$possibleStatusesArr = array(Leave::LEAVE_STATUS_LEAVE_REJECTED => $lang_Leave_Common_Rejected, Leave::LEAVE_STATUS_LEAVE_APPROVED  => $lang_Leave_Common_Approved);
?>

<h2><?php echo $lang_Leave_Leave_list_Title1 ?><hr/></h2>
<?php if (isset($_GET['message']) && $_GET['message'] != 'xx') {

	$expString  = $_GET['message'];
	$expString = explode ("_",$expString);
	$length = count($expString);

	$col_def=strtolower($expString[$length-1]);

	$expString='lang_Leave_'.$_GET['message'];
	if (isset($$expString)) {
?>
	<font class="<?php echo $col_def?>" size="-1" face="Verdana, Arial, Helvetica, sans-serif">
<?php echo $$expString; ?>
	</font>
<?php
	}
}
?>

<?php if (!is_array($records)): ?>
    <h5><?php echo $lang_Error_NoRecordsFound; ?></h5>
<?php else: ?>
<form id="frmCancelLeave" name="frmCancelLeave" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?leavecode=Leave&action=Leave_Cancel">

<table border="0" cellpadding="0" cellspacing="0">
  <thead>
  	<tr>
            <th class="tableTopLeft"></th>
            <th class="tableTopMiddle" colspan="8"></th>    	           
            <th class="tableTopRight"></th>
	</tr>
        
	<tr>
            <th class="tableMiddleLeft"></th>
            <th width="100px" class="tableMiddleMiddle"><?php echo $lang_Leave_Common_Date;?></th>    	    	
            <th width="50px" class="tableMiddleMiddle"><?php echo $lang_Leave_NoOfDays;?></th>    	              	
            <th width="50px" class="tableMiddleMiddle"><?php echo $lang_Leave_Common_LeaveType;?></th>
            <th width="100px" class="tableMiddleMiddle"><?php echo "Supervisor";?></th>
            <th width="100px" class="tableMiddleMiddle"><?php echo "Program manager" ?></th>
            <th width="100px" class="tableMiddleMiddle"><?php echo $lang_Leave_Period;?></th>
            <th width="100px" class="tableMiddleMiddle"><?php echo $lang_Leave_Common_Comments;?></th>
            <th width="100px" class="tableMiddleMiddle">Actions</th>
            <th class="tableMiddleRight"></th>
	</tr>
  </thead>
  <tbody>
<?php
    $j = 0;
    if (is_array($records))
        foreach ($records as $record) {
           
        $cssClass = $j%2?'even':'odd';$j++;
        $dateStr = LocaleUtil::getInstance()->formatDate($record->getLeaveFromDate());
        $toDate = LocaleUtil::getInstance()->formatDate($record->getLeaveToDate());
        if (!empty($toDate)) {
               $dateStr .=	" -> ".$toDate;
        }
?>
  <tr>
    <td class="tableMiddleLeft"></td>
    <td class="<?php echo $cssClass; ?>"><?php echo $dateStr; ?></td>            
    <td class="<?php echo $cssClass; ?>"><?php echo round($record->getNoDays(),2); ?></td>          
    <td class="<?php echo $cssClass; ?>"><?php echo $record->getLeaveTypeName(); ?></td>
    <td class="<?php echo $cssClass; ?>">
    <?php echo $statusArr[$record->getLeaveHR_Status()]; ?>
        <input type="hidden" name="cmbHR_Status[]" value="<?php echo $record->getLeaveHR_Status(); ?>" />
    </td>
    <td class="<?php echo $cssClass; ?>">
    <input type="hidden" name="id[]" value="<?php echo $record->getLeaveRequestId(); ?>" />    
     <?php echo $statusArr[$record->getLeaveStatus()]; ?>
        <input type="hidden" name="cmbStatus[]" value="<?php echo $record->getLeaveStatus(); ?>" />
    </td>
    <td class="<?php echo $cssClass; ?>"><?php
    		$leaveLength = null;
    		if (($record->getStartTime() != null) && ($record->getEndTime() != null) && ($record->getStartTime() != $record->getEndTime())) {
    			$leaveLength = "{$record->getStartTime()} - {$record->getEndTime()}";
    		} else if ($record->getLeaveLengthHours() != null) {
    			$leaveLength = "{$record->getLeaveLengthHours()} {$lang_Common_Hours}";
    		} else {
    			$leaveLength = '----';
    		}
    		echo $leaveLength;
    ?></td>
        <td class="<?php echo $cssClass; ?>">
            <textarea type="text" name="txtComment[]" ><?php echo $record->getLeaveComments(); ?></textarea>
	    <input type="hidden" name="txtEmployeeId[]" value="<?php echo $record->getEmployeeId(); ?>" />
	</td>
        <td class="<?php echo $cssClass; ?>">
            <?php if ($record->getLeaveStatus() != Leave::LEAVE_STATUS_LEAVE_CANCELLED 
                    && $record->getLeaveStatus() != Leave::LEAVE_STATUS_LEAVE_TAKEN 
                    && $record->getLeaveStatus() != Leave::LEAVE_STATUS_LEAVE_REJECTED):?>
            <?php if ($record->getLeaveHR_Status() != Leave::LEAVE_STATUS_LEAVE_APPROVED):?>
            <a href="<?php echo $_SERVER['PHP_SELF']; ?>?leavecode=Leave&action=View_Leave_Edit&id=<?php echo $record->getLeaveRequestId(); ?>">Edit</a>
            <?php endif;?>
            <a href="<?php echo $_SERVER['PHP_SELF']; ?>?leavecode=Leave&action=Leave_Cancel&id=<?php echo $record->getLeaveRequestId(); ?>">Cancel</a>
            <?php endif;?>
        </td>
	<td class="tableMiddleRight"></td>
        
  </tr>

<?php
		}
?>
  </tbody>
  <tfoot>
    <tr>
        <td class="tableBottomLeft"></td>
        <td class="tableBottomMiddle" colspan="8"></td>
        <td class="tableBottomRight"></td>
    </tr>
</tfoot>
</table>
<p id="controls">
<input type="image" name="Save" class="save" src="../../themes/beyondT/pictures/btn_save.gif"/>
</p>
</form>
<?php endif; ?>

